package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysGoodsParise;
import com.ruoyi.project.system.service.ISysGoodsPariseService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobileUser/goodsParise/")
public class UserGoodsPariseController extends BaseController {

    @Autowired
    private ISysGoodsPariseService sysGoodsPariseService;

    /**
     * 用户新增点赞
     *  需要登录  ~~~  不可重复点赞 取消点赞
     *  传 goodsId
     * */
    @SignatureValidation
    @PostMapping("insertParise")
    @RepeatSubmit
    public AjaxResult insertParise(@RequestBody SysGoodsParise sysGoodsParise){
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysGoodsParise.setMobileUserId(mobileUserId);
        sysGoodsPariseService.insertSysGoodsParise(sysGoodsParise);
        int count = sysGoodsPariseService.pariseCount(sysGoodsParise);
        return AjaxResult.success(count);
    }
    /**
     * 用户取消点赞
     *  需要登录  ~~~  不可重复点赞 取消点赞
     *  传 pariseId goodsId
     * */
    @SignatureValidation
    @PostMapping("deleteParise")
    @RepeatSubmit
    public AjaxResult deleteParise(@RequestBody SysGoodsParise sysGoodsParise){
        sysGoodsPariseService.deleteSysGoodsPariseById(sysGoodsParise.getPariseId());
        int count = sysGoodsPariseService.pariseCount(sysGoodsParise);
        return AjaxResult.success(count);
    }
}
